package web;

import pojo.PageBean;
import pojo.User;
import service.Impl.UserServiceImpl;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findUserByPage")
public class FindUserByPageServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String curPage = request.getParameter("currentPage");
        String pSize = request.getParameter("pageSize");
        if(curPage== null || curPage.equals("")){
            curPage= "1" ;
        }
        if(pSize== null || pSize.equals("")){
            pSize = "2" ;
        }
        int currentPage = Integer.parseInt(curPage) ;
        int pageSize = Integer.parseInt(pSize) ;
        UserService userService = new UserServiceImpl() ;
        PageBean<User> pb = userService.findUserByPage(currentPage,pageSize) ;
        System.out.println(pb);
        if(pb!=null){
            request.setAttribute("pb",pb) ;
            request.getRequestDispatcher("/admin/userList.jsp").forward(request,response);
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            doGet(request,response);
    }


}
